<template>
  <div class="app-container">
    <div class="search-container">
      <div class="search-wrap">
        <!-- <div style="display:inline-block;">
          <label class="radio-label" style="padding-left:0;">网络名称: </label>
          <el-input v-model="fieldName" placeholder="" style="width:240px;"/>
        </div>

        <div style="display:inline-block;">
          <label class="radio-label">网段: </label>
          <el-input v-model="fieldName" placeholder="" style="width:240px;"/>
        </div>
        <el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="primary" icon="el-icon-search">
          搜索
        </el-button>
        <el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="info" icon="el-icon-refresh-right">
          重置
        </el-button> -->
      </div>

      <div class="btn-wrap radio-label">
        <el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="primary" icon="el-icon-circle-plus-outline"
        @click="dialogTableVisible = true">
          新增
        </el-button>
      </div>
    </div>

    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading..." fit highlight-current-row>
      <el-table-column align="center" label="编号" width="95">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="安全组名称"  width="200">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="安全检测库">
        <template slot-scope="scope">
          {{ scope.row.text }}
        </template>
      </el-table-column>
      <el-table-column label="告警次数"  width="120">
        <template slot-scope="scope">
          {{ scope.row.number }}
        </template>
      </el-table-column>
      <el-table-column label="危险等级" width="120">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.level == '高'" size="mini">{{ scope.row.level }}</el-tag>
          <el-tag type="warning" v-if="scope.row.level == '中'" size="mini">{{ scope.row.level }}</el-tag>
          <el-tag type="success" v-if="scope.row.level == '低'" size="mini">{{ scope.row.level }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="260" align="center">
        <template slot-scope="{row}">
          <el-button
                type="warning"
                size="mini"
                icon="el-icon-edit"
              >
                修改
              </el-button>

          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
          >
            删除
          </el-button>
        </template>
        
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="1000">
      </el-pagination>
    </div>


    <el-dialog v-el-drag-dialog :visible.sync="dialogTableVisible" title="新增" width="1200px">
      <el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="安全组名称" prop="title">
              <el-input value="高攻策略安全" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <div class="form-title">
              <span>安全检测库配置</span>
              <el-button style="margin-left: 30px;" type="primary" size="mini">选择检测库</el-button>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-table v-loading="listLoading" :data="formList" element-loading-text="Loading..." fit highlight-current-row>
              <el-table-column align="center" label="编号" width="95">
                <template slot-scope="scope">
                  {{ scope.$index + 1 }}
                </template>
              </el-table-column>
              <el-table-column label="威胁名称">
                <template slot-scope="scope">
                  {{ scope.row.name }}
                </template>
              </el-table-column>
              <el-table-column label="危险级别">
                <template slot-scope="scope">
                  <el-tag type="danger" v-if="scope.row.level == '高'" size="mini">{{ scope.row.level }}</el-tag>
                  <el-tag type="warning" v-if="scope.row.level == '中'" size="mini">{{ scope.row.level }}</el-tag>
                  <el-tag type="success" v-if="scope.row.level == '低'" size="mini">{{ scope.row.level }}</el-tag>
                </template>
              </el-table-column>

              <el-table-column label="操作" width="150" align="center">
                <template slot-scope="{row}">
                  <el-button
                    type="danger"
                    size="mini"
                  >
                    移除
                  </el-button>
                </template>
                
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">
          取消
        </el-button>
        <el-button type="primary" @click="dialogTableVisible = false">
          确认
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { fetchList } from '@/api/article'

import Pagination from '@/components/Pagination'
import elDragDialog from '@/directive/el-drag-dialog'

export default {
  name: 'Secure',
  components: { Pagination },
  directives: { elDragDialog },
  data() {
    return {
      list: null,
      fieldName: '',
      listLoading: true,
      downloadLoading: false,
      autoWidth: true,

      dialogTableVisible: false,
      formList: [
        {
          name: 'TCP攻击',
          level: '高'
        },
        {
          name: 'ICMP扫描',
          level: '中'
        },
        {
          name: 'TCP攻击',
          level: '高'
        },
        {
          name: 'ARP扫描',
          level: '高'
        },
        {
          name: '目录注入攻击',
          level: '低'
        },
      ],
      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      temp: {
        id: undefined,
        importance: 1,
        remark: '',
        timestamp: new Date(),
        title: '',
        type: '',
        status: 'published',
        outEth: ['eth0'],
        inEth: 'eth1',
        netType: '静态网络'
      },
      honeypotOptions: ['telnet蜜罐', 'SSH蜜罐', 'FTP蜜罐','DNS蜜罐', 'MAIL蜜罐', 'SMB蜜罐','SFTP蜜罐'],
      ipOptions: ['172.16.10.2', '172.16.10.3','172.16.10.4', '172.16.10.5','172.16.10.6', '172.16.10.7','172.16.10.8','172.16.10.9','172.16.10.10']
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      let data = []
      fetchList().then(response => {
        data.push({
          name: "检测库01",
          text: "ARP扫描、TCP扫描、ICMP扫描、暴力破解、SQL注入...",
          number: 57,
          level: '高'
        })
        data.push({
          name: "检测库12",
          text: "TCP攻击、UDP攻击、CK攻击、Smurf Ddos攻击、HTTP 攻击、APDos攻迥...",
          number: 20,
          level: '中'
        })
        data.push({
          name: "检测库03",
          text: "ACK攻击、Smurf Ddos攻击、HTTP 攻击、APDos攻迥、XSS攻击、反射XSS攻击、SQL注入攻击...",
          number: 1000,
          level: '高'
        })
        data.push({
          name: "检测库08",
          text: "XSS攻击、反射XSS攻击、SQL注入攻击、目录注入攻击、UDP攻击...",
          number: 103,
          level: '低'
        })
        this.list = data
        this.listLoading = false
      })
    },
  }
}
</script>

<style scoped>
.radio-label {
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 30px;
}
.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: right;
}
.search-container {
  display: flex;
  justify-content: space-between;
}
.search-wrap {
  flex: 1;
}
</style>